Skip to content

Fix any/all for int8 and uint8 on Metal - #4755

Merged
zcbenz merged 2 commits into
ml-explore:mainfrom
MarcosAsh:fix/metal-any-int8
Oct 25, 2026
Merged

zcbenz merged 2 commits into
ml-explore:mainfrom
MarcosAsh:fix/metal-any-int8

Conversation

@MarcosAsh

Copy link
Copy Markdown
Contributor
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure:
    I used AI to help me find this bug. All code is mine and I did all of the testing.

mx.any is wrong on Metal for int8/uint8 when the nonzero values are even:

mx.any(mx.array([0, 2], dtype=mx.int8))  # False on GPU, True on CPU

remap_reduce_types sends every 1-byte dtype to the bool and/or kernels, so int8/uint8 bytes get read as Metal bool. Metal assumes a bool byte is 0 or 1, and several of the kernels only test the low bit, so a 2 reads as false.
mx.all happens to come out right but reads the same bad data. Been there since #1607.

I added test_and_or_small_ints: even int8/uint8 values over the all, row, multi-axis and column paths. 8 subtests fail on main on Metal, all pass with the fix. Existing tests only use 0 and 1 so never hit this.

Full Python suite passes apart from test_init_reduce_large_output, which errors on main too: it asks for a 4 GiB buffer and the GitHub runner caps at 3.5 GiB, so you'll see the same on a smaller Mac. I ran both wheels through 108 any/all cases on int8, uint8 and bool. Main gets 8 wrong and the patched one gets 0.

Perf: the int8 kernels are within noise of bool, but that was on CI runners' that vary 1.1 to 2x even on untouched code.

Doesn't fix a uint8 array viewed as bool_, since a bool input still gets the bool kernel.

@zcbenz
zcbenz force-pushed the fix/metal-any-int8 branch from ff80efc to f1887b0 Compare October 25, 2026 09:58
@zcbenz
zcbenz merged commit 83df5f0 into ml-explore:main Oct 25, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants